using System;
using System.Data;

namespace Dbam.DbFramework
{
	/// <summary>
	/// Attribute that defines the mapping of an entity's property to a column in a relational database.
	/// </summary>
	[AttributeUsage(AttributeTargets.Property, AllowMultiple=false, Inherited=true)]
	public class ColumnAttribute
		: Attribute
	{
		#region Data Members

		/// <summary>
		/// The name of the column in the relational database the property maps to.
		/// </summary>
		private string _columnName;

		/// <summary>
		/// The data type in the relational database.
		/// </summary>
		private DbType _dbType;

		/// <summary>
		/// Flag indicating whether the property maps to a primary key column in the relational database.
		/// </summary>
		private bool _isPrimaryKey;

		#endregion

		#region Constructor(s)

		/// <summary>
		/// Initialize the column mapping information.
		/// </summary>
		/// <param name="columnName">The name of the column the property maps to.</param>
		/// <param name="dbType">The data type of the column in the relational database.</param>
		/// <param name="isPrimaryKey">Flag indicating whether the property maps to a primary key.</param>
		public ColumnAttribute(string columnName, DbType dbType, bool isPrimaryKey)
		{
			_columnName = columnName;
			_dbType = dbType;
			_isPrimaryKey = isPrimaryKey;
		}

		#endregion

		#region Properties

		/// <summary>
		/// Gets the name of the column the property maps to.
		/// </summary>
		public string ColumnName
		{
			get { return _columnName; }
		}

		/// <summary>
		/// Gets the data type of the column.
		/// </summary>
		public DbType DbType
		{
			get { return _dbType; }
		}

		/// <summary>
		/// Gets the flag indicating whether the column is a primary key column.
		/// </summary>
		public bool IsPrimaryKey
		{
			get { return _isPrimaryKey; }
		}

		#endregion
	}
}